package com.to8to.kitt.esb;

import io.netty.buffer.ByteBuf;

import org.apache.thrift.protocol.TMessage;
import org.apache.thrift.protocol.TMessageMeta;
import org.apache.thrift.protocol.TMessageType;

public class BusMessage {
	
	private TMessage head;
	private TMessageMeta meta;
	private ByteBuf buff;
	
	public BusMessage(TMessage head, ByteBuf buff )
	{
		this.head = head;
		this.buff = buff;
	}
	
	public BusMessage()
	{
		
	}
	
	public String msgKey(int seqid)
	{
		return head.name + "-" + seqid;
	}
	
	public TMessageMeta getMeta() {
		return meta;
	}

	public void setMeta(TMessageMeta meta) {
		this.meta = meta;
	}

	public String msgKey()
	{
		return head.name + "-" + head.seqid;
	}
	
	public TMessage getHead() {
		return head;
	}
	public void setHead(TMessage head) {
		this.head = head;
	}
	public ByteBuf getBuff() {
		return buff;
	}
	public void setBuff(ByteBuf buff) {
		this.buff = buff;
	}
	
	public boolean isCall() {
		return head.type == TMessageType.CALL;
	}

	public boolean isReply() {
		return head.type == TMessageType.REPLY;
	}

	public boolean isException() {
		return head.type == TMessageType.EXCEPTION;
	}
	
	
	public void setSeqid(int seqid) {
		this.head = new TMessage(head.name, head.type, seqid);
	}

	public int getSeqid() {
		return head.seqid;
	}
	
}
